<template>
	<view>
		<scroll-view scroll-y="true" @scrolltolower="lower" style="height: 100vh;">
			<view class="hei20"></view>
			<view class="item" v-for="(item,index) in list" :key="index" @click="details(item.id)">
				<view class="leftimg">
					<img :src="item.thumb" alt="" />
				</view>
				<view class="righttext">
					<view class="foSi32 mar-top15">{{item.title}}</view>
					<view class="content">
						{{item.mainwork}}
					</view>
					<view class="dis disAl disJuB mar-top10">
						<view class="foSi24">
							{{item.begintime}}到{{item.endtime}}
						</view>
						<!-- <view v-if="item.bm === 0" class="foSi28 dis disAl disJuC hei60 borRad40 coFFF"
							style="width: 180rpx;background: #3978F9;" @click.stop="baoming(item.id,item.companyid)">报名
						</view> -->
					</view>
				</view>
			</view>
			<view v-if="list.length == 0" class="wid90 mar fowe800 foSi35">
				<view style="height: 50rpx;"></view>
				<view class="dis disJuC">
					<image src="../../static/imgs/icon/zanwu1.png" style="width: 400rpx;height: 300rpx;"></image>
				</view>
				<view class="textCen mar-top20" style="color: #868686;">暂无数据</view>
			</view>
			<view class="hei20"></view>
		</scroll-view>
	</view>
</template>

<script>
	import {
		Notice
	} from '../../model/notice-model.js';
	var notice = new Notice();
	export default {
		data() {
			return {
				page: 1,
				last_page: 0,
				list: [],
				vitae: 0,
				type:1
			}
		},
		onLoad(option) {
			if(option.type){
				this.type = option.type
			}
			this.getVitae()
			this.getlist()
			
		},
		methods: {
			getVitae(){
				var that = this
				let params = {}
				notice.curriculumVitae((data) => {
					console.log(data)
					if (data.code === 0) {
						that.vitae = data.data
					} else {
						uni.showToast({
							title: data.msg,
							icon: 'none',
							duration: 2000
						})
					}
				}, params)
			},
			baoming(id, companyid) {
				var that = this
				if(that.vitae === 0){
					return uni.showToast({
						title: '请提交简历',
						icon: 'none',
						duration: 2000
					})
				}
				if(!uni.getStorageSync('token')){
					return uni.navigateTo({
						url:'/pages/login/index'
					})
				}
				let params = {
					aid: id,
					companyid: companyid
				}
				uni.showModal({
					title: '提示',
					content: '确认报名该招聘吗',
					success: (res) => {
						if (res.confirm) {
							notice.signupActive((data) => {
								console.log(data)
								if (data.code === 0) {
									uni.showToast({
										title: '报名成功',
										icon: 'none',
										duration: 2000
									})
									that.getlist()
								} else {
									uni.showToast({
										title: data.msg,
										icon: 'none',
										duration: 2000
									})
								}
							}, params)
						} else if (res.cancel) {
							// 用户点击了取消按钮
							console.log('用户取消了授权');
						}
					}
				});

			},
			details(id){
				if(this.type == 1){
					uni.navigateTo({
						url:'/pages/noticedetail/details?id='+id
					})
				}else {
					uni.navigateTo({
						url:'/pages/noticedetail/fairdetails?id='+id
					})
				}
				
			},
			lower(e) {
				if (this.last_page > this.page) {
					this.page++
					this.getlist()
				}
			},
			getlist() {
				var that = this
				let params = {
					// page: that.page
				}
				if(that.type == 1){
					notice.activeList((data) => {
						console.log(data)
						if (data.code === 0) {
							// that.last_page = data.data.last_page
							// that.list = that.page === 1?data.data.data:that.list.concat(data.data.data)
							that.list = data.data
						} else {
							uni.showToast({
								title: data.msg,
								icon: 'none',
								duration: 2000
							})
						}
					}, params)
				}else if(that.type == 2){
					notice.jobfairList((data) => {
						console.log(data)
						if (data.code === 0) {
							// that.last_page = data.data.last_page
							// that.list = that.page === 1?data.data.data:that.list.concat(data.data.data)
							that.list = data.data
						} else {
							uni.showToast({
								title: data.msg,
								icon: 'none',
								duration: 2000
							})
						}
					}, params)
				}
				
			}
		}
	}
</script>

<style>
	page {
		background-color: #f1f1f1;
	}

	.item {
		padding: 20rpx;
		border-radius: 10rpx;
		display: flex;
		background-color: #fff;
		margin-bottom: 20rpx;
	}

	.leftimg {
		width: 25%;
	}

	.leftimg img {
		width: 100%;
		border-radius: 10rpx;
	}

	.righttext {
		margin-left: 10rpx;
		display: flex;
		flex-direction: column;
		width: 75%;
	}

	.content {
		overflow: hidden; //超出的文本隐藏
		display: -webkit-box;
		-webkit-line-clamp: 2; // 超出多少行
		-webkit-box-orient: vertical;
		margin-top: 10rpx;
	}
</style>